package com.dingwei.lesyndrome.mvp.presenter;

import android.text.TextUtils;

import com.dingwei.lesyndrome.base.FailsBean;
import com.dingwei.lesyndrome.base.MyBaseBean;
import com.dingwei.lesyndrome.bean.CheckBean;
import com.dingwei.lesyndrome.custom.myCallback;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.w3c.dom.Text;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.List;

/**
 * Created by lihao on 2017/9/12.
 */

public class CircleReportPresenter extends basePresenter {

    private Contract.CircleReportView circleReportView;

    public CircleReportPresenter(Contract.CircleReportView view) {
        super(view);
        this.circleReportView = view;
    }

    public void reportCircle(final String cid, List<CheckBean> type, String content) {

        String typeStr = "";
        for (int i = 0; i < type.size(); i++) {
            if (type.get(i).isCheck){
                typeStr = type.get(i).name;
                break;
            }
        }
        if (TextUtils.isEmpty(typeStr)) {
            showToast("请选择举报类型");
            return;
        }
        if (TextUtils.isEmpty(content)) {
            showToast("请输入举报原因");
            return;
        }

        RequestParams rp = new RequestParams(URLS.HOST+URLS.REPORT_CIRCLE);
        rp.addBodyParameter("cid", cid);
        rp.addBodyParameter("type", typeStr);
        rp.addBodyParameter("content", content);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        x.http().post(rp, new myCallback(BaseActivity.context, MyBaseBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                showToast("举报成功");
                circleReportView.reportCircleSuccess();
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
            }
        });
    }
}
